<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>编辑课程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../static/layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../static/layuimini/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>

    <script src="../../../static/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../../static/layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src1="http://local.res.layui.com/layui/release/laydate/dist/laydate.js" charset="utf-8"></script>

    <script type="text/javascript" charset="UTF-8">
        //获取url里，以name为名字的参数内容
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = decodeURI(window.location.search.substr(1).match(reg));
            var arr = r.split(",");
            if (r != null) return arr[2];
            return null;
        }
    </script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form" lay-filter="first">
            <div class="layui-form-item">
                <label class="layui-form-label required">课程名称</label>
                <div class="layui-input-block">
                    <input type="text" name="curriculumName" lay-verify="required" lay-reqtext="课程名称不能为空"
                           placeholder="请输入课程名称"
                           value="" class="layui-input" id="curriculumName">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">课程类型</label>
                <div class="layui-input-block">
                    <select name="curriculumType" data-value="" lay-verify="required" lay-verType="tips"
                            lay-filter="curriculumType" id="curriculumType">
                        <option value="">请选择课程类型</option>
                        <option value="公共课">公共课</option>
                        <option value="专业课">专业课</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">课程性质</label>
                <div class="layui-input-block">
                    <select name="curriculumCharacteristics" data-value="" lay-verify="required" lay-verType="tips"
                            lay-filter="curriculumCharacteristics" id="curriculumCharacteristics">
                        <option value="">请选择课程性质</option>
                        <option value="理论课">理论课</option>
                        <option value="实践课">实践课</option>
                        <option value="理论实践课">理论实践课</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">学分</label>
                <div class="layui-input-block">
                    <input type="text" name="credit" lay-verify="required" lay-reqtext="学分不能为空"
                           placeholder="请输入学分"
                           value="" class="layui-input" id="credit">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'miniTab', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.jquery;

        //ajax回填数据
        $.get("/getCurriculumById", {curriculumId: getQueryString("curriculumId")}, function (data) {
            form.val('first', {
                'curriculumName': data.curriculumName
                , 'curriculumCharacteristics': data.curriculumCharacteristics
                , 'credit': data.credit
                , 'curriculumType': data.curriculumType
            });
        }, "json");


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let curriculumName = $("#curriculumName").val();
            let curriculumType = $("#curriculumType").val();
            let curriculumCharacteristics = $("#curriculumCharacteristics").val()
            let credit = $("#credit").val();
            console.log("curriculumName = " + curriculumName);
            $.get("/editCurriculum", {
                curriculumId: getQueryString("curriculumId"),
                curriculumName: curriculumName,
                curriculumType: curriculumType,
                curriculumCharacteristics: curriculumCharacteristics,
                credit: credit
            }, function (data) {
                if (data == "success") {
                    layer.msg('课程编辑成功', {
                        icon: 6,
                        time: 1000, //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // parent.layer.closeAll('iframe');
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.window.location.reload();//刷新页面
                    });
                } else {
                    layer.msg('课程编辑失败，请稍后再试！', {
                        icon: 7,
                        time: 1000, //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // parent.layer.closeAll('iframe');
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }
            }, "text");

        });


        //事件监听

        form.on('select(curriculumType)', function (data) {
            console.log('select.curriculumType：', this, data);
        });
        form.on('select(curriculumCharacteristics)', function (data) {
            console.log('select.curriculumCharacteristics：', this, data);
        });

    });
</script>

</body>
</html>